package com.ityedao.随机数;

import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        int correctNum = r.nextInt(100) + 1;
        while (true) {
            System.out.println("请输入您猜测的数字（1-100）：");
            try {
                int guessNum = sc.nextInt();

                if (guessNum < correctNum){
                    System.out.println("数字过小~");
                    continue;
                } else if (guessNum > correctNum) {
                    System.out.println("数字过大~");
                    continue;
                } else if (guessNum == correctNum) {
                    System.out.println("恭喜猜中~正确数字为：" + correctNum);
                    break;
                }
            } catch (Exception e) {
                System.out.println("数据错误！");
                break;
            }
        }
    }
}
